$(function() {
	easyExt.initUrl('/data_qBank');
	easyExt.init();//初始化表格
});

function viewOption(){
	var selRows=$('#dg').datagrid('getSelections');//返回选中行
	if(selRows.length==0){
		$.messager.alert("提示", "请选择要修改的用户角色！", "info");  
		return;
	}else if(selRows.length==1){
		getOption(selRows[0]);
	}else{
		$.messager.alert("提示", "只能单项修改,请选择一行！", "info");
	}
}
function getOption(bank){
	var json={};
	var optionId="";
	$('#qOption').dialog({
		title:'题库答案管理',  
		buttons:[{
				text:'确认',
				handler:function(){
					var options=$('#qo_dg').datagrid('getSelections');
					for(var i=0,j=options.length;i<j;i++){
						optionId+=options[i].id+",";
					}
					easyExt.ajax($u.getRootPath()+"/data_qBank/saveOption?bankId="+bank.id+"&optionId="+optionId,"POST",{});
					$('#qOption').dialog('close');
				}
			},{
				text:'取消',
				handler:function(){
					$('#qOption').dialog('close');
			}
	    }]
	});
	$('#qOption').dialog('open');
	$('#qo_dg').datagrid({
		 url: $u.getRootPath()+'/data_qOption/list1?bankId='+bank.id,
		 striped: true,
		 fit : true,
		 method: 'get',
		 autoRowHeight:false,
		 pagination: true,
		 showRefresh: true,
		 pagePosition: 'bottom',
		 idField: 'id',
		 fitColumns: true,
		 rownumbers: true,
		 onLoadSuccess:function(){
		    $.ajax({
		    	async:false,
				type:'get',
		    	dataType: 'json',
		    	timeout: 5000,
		    	data:{bankId:bank.id},
				url:$u.getRootPath()+'/data_qBank/getOption'
		    }).done(function(data, status, xhr){
				if(data){
					for(var i=0,j=data.length;i<j;i++){
						$('#qo_dg').datagrid('selectRecord',data[i].id);
					}
				} 
		    }).fail(function(data, status, xhr){
	    		$.messager.alert("提示", "请求失败！", "info");
	    		return;
		    });
		 }
	 });
}

function formater1(value,row,index){
	  if(row.isRight==1){
	    return '正确';
	  }else{
	    return '错误';
	  }
}
